package cn.edu.nuc.ssm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.ssm.dao.CarMapper;
import cn.edu.nuc.ssm.dto.PageInfo;
import cn.edu.nuc.ssm.entity.Car;
import cn.edu.nuc.ssm.service.interfaces.CarService;

@Service
public class CarServiceImpl implements CarService {

	@Autowired
	private CarMapper carMapper;

	@Override
	public int savecar(Car car) {
	
		return carMapper.insert(car);
	}

	@Override
	public PageInfo listWidthPage(int current, String carName) {
		
		int count = carMapper.count(carName);
		
		PageInfo pageInfo = new PageInfo();
		pageInfo.setCount(count);
		
		pageInfo.setCurrent(current);
		
		List<Car> list = carMapper.listWithPage(current,pageInfo.getStart(),pageInfo.getOffset(),carName);
		
		pageInfo.setList(list);
		
		return pageInfo;
	}

	@Override
	public int delete(int id) {
		
		return carMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Car findCarByid(int id) {
	
		return carMapper.selectByPrimaryKey(id);
	}

	@Override
	public int update(Car car) {
		
		return carMapper.updateByPrimaryKey(car);
	}
	
	
}
